package cn.livingCloud.dto;

import cn.livingCloud.entity.system.Setting;
import cn.livingCloud.wechat.protocol.WechatAccessToken;
import org.apache.commons.lang.StringUtils;

/**
 * Created by DingJie  on 2016/1/19.
 */
public class SettingFromDto {
    private String uuid;
    //应用名称
    private String name;
    //微信appid
    private String appid;
    //微信secret
    private String secret;
    //微信token
    private String token;
    //公告
    private String notes;
    //模板消息ID
    private String templateId;
    //模板消息内容
    private String templateContent = "{\n" +
            "    \"touser\": \"${open}\",\n" +
            "    \"template_id\": \"${templateId}\",\n" +
            "    \"url\": \"${url}\",\n" +
            "    \"data\": {\n" +
            "        \"key1\": {\n" +
            "            \"value\": \"val1\",\n" +
            "            \"color\": \"#173177\"\n" +
            "        },\n" +
            "        \"key2\": {\n" +
            "            \"value\": \"欢迎！\",\n" +
            "            \"color\": \"#173177\"\n" +
            "        }\n" +
            "    }\n" +
            "}";

    private String accessToken;

    public SettingFromDto() {
    }

    public SettingFromDto(Setting setting) {
        this.uuid = setting.getUuid();
        this.name = setting.getName();
        this.appid = setting.getAppid();
        this.secret = setting.getSecret();
        this.token = setting.getToken();
        this.notes = setting.getNotes();
        this.templateId = setting.getTemplateId();
        String templateContent = setting.getTemplateContent();
        if (StringUtils.isNotEmpty(templateContent)) {
            this.templateContent = templateContent;
        }
        this.accessToken = WechatAccessToken.getInstance().getToken(appid, secret);
    }

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAppid() {
        return appid;
    }

    public void setAppid(String appid) {
        this.appid = appid;
    }

    public String getSecret() {
        return secret;
    }

    public void setSecret(String secret) {
        this.secret = secret;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public String getNotes() {
        return notes;
    }

    public void setNotes(String notes) {
        this.notes = notes;
    }

    public String getTemplateContent() {
        return templateContent;
    }

    public SettingFromDto setTemplateContent(String templateContent) {
        this.templateContent = templateContent;
        return this;
    }

    public String getTemplateId() {
        return templateId;
    }

    public SettingFromDto setTemplateId(String templateId) {
        this.templateId = templateId;
        return this;
    }

    public String getAccessToken() {
        return accessToken;
    }

    public SettingFromDto setAccessToken(String accessToken) {
        this.accessToken = accessToken;
        return this;
    }
}
